package com.gitee.wsl.mathematics.matrix.mat2

import com.gitee.wsl.ext.array.FloatArray
import com.gitee.wsl.io.dataproxy.DataGet
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.matrix.M
import com.gitee.wsl.mathematics.matrix.N
import com.gitee.wsl.mathematics.vector.vec2.Vec2f


open class Mat2f(m00: Float=0.0f, m01: Float=0.0f,
                 m10: Float=0.0f, m11: Float=0.0f,
                 override val proxy: DataGet<Float> = FloatArray(m00, m01,m10, m11).asProxy())
    :Matrix2F<Mat2f, Vec2f> {

    override val self
        get() = this

    override val m by lazy{listOf(M[0],M[1])}

    override val n by lazy {listOf(N[0],N[1])}

    override fun createVec(indexes: List<Int>) = Vec2f(proxy = proxy.asProxy(indexes))

    override fun createVec2(x: Float, y: Float) = Vec2f(x,y)

    override fun toMutable() = MutableMat2f(this)

    override fun create(m00: Float, m01: Float, m10: Float, m11: Float) = Mat2f(m00, m01, m10, m11)

    override fun hashCode(): Int =
        m00.hashCode() xor
                (m01.hashCode() xor 0x75A5A5A5) xor
                (m10.hashCode() xor 0x5A5A5A5A) xor
                (m11.hashCode() xor 0x76969696)

    override fun equals(other: Any?) =
        other is Mat2f &&
                m00 approx  other.m00 &&
                m01 approx other.m01 &&
                m10 approx other.m10 &&
                m11 approx other.m11

    override fun toString() = "(($m00, $m01),\n ($m10, $m11))"

}
